package com.ibeeking.found.org.b.rest.controller.v1;

import com.ibeeking.found.org.b.rest.service.IOrgPositionService;
import com.ibeeking.found.org.service.common.param.OrgPositionParam;
import com.ibeeking.found.org.service.common.query.OrgPositionQuery;
import com.ibeeking.found.org.service.common.vo.OrgPositionVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName OrgPositionController
 * @Description
 * @Author ibeeking
 * @Date 2021-01-29 14:48
 **/
@RestController
@RequestMapping("/b/position/v1")
public class OrgPositionController {

    @Resource
    private IOrgPositionService orgPositionServiceImpl;

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "职务列表")
    @PostMapping(value = "/list")
    public List<OrgPositionVO> list(@RequestBody OrgPositionQuery query) {
        return orgPositionServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "职务列表")
    @PostMapping(value = "/listAllAndSub")
    public List<OrgPositionVO> listAllAndSub(@RequestBody OrgPositionQuery query) {
        return orgPositionServiceImpl.listAllAndSub(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "职务添加")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) OrgPositionParam param) {
        return orgPositionServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "职务修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) OrgPositionParam param) {
        return orgPositionServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "职务查看")
    @GetMapping(value = "/view/{id}")
    public OrgPositionVO view(@PathVariable("id") Long id) {
        return orgPositionServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "职务状态修改")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return orgPositionServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "职务删除")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return orgPositionServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "基于部门id查询职务列表")
    @PostMapping(value = "/queryByDepartmentId/{departmentId}")
    public List<OrgPositionVO> queryByDepartmentId(@PathVariable("departmentId") Long departmentId) {
        return orgPositionServiceImpl.queryByDepartmentId(departmentId);
    }

}